﻿using System;
using System.Data;
public partial class Reservation4: MemberPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        xrReservation report = new xrReservation();
        Viewer.Report = report;
        if (!Page.IsPostBack)
        {
            /*
            string cnnCe = System.Configuration.ConfigurationManager.ConnectionStrings["ce"].ConnectionString;
            ConfExpert.Utility.Data.DataManager dmCe = new ConfExpert.Utility.Data.DataManager(cnnCe);

            string xmlRezerve = "<MyData><Rezerve><BrandId>8</BrandId><SezonId>1</SezonId><SODetay>tt</SODetay><Notes>tt</Notes><RezerveSuresi>14</RezerveSuresi><ReservedBy>tt</ReservedBy><email>tt</email></Rezerve></MyData>";

            string xmlRezerveLines = "<SelectedProducts><SelectedProduct><ProductId>13</ProductId><RollId>13175</RollId></SelectedProduct><SelectedProduct><ProductId>13</ProductId><RollId>13176</RollId></SelectedProduct><SelectedProduct><ProductId>13</ProductId><RollId>13175</RollId></SelectedProduct><SelectedProduct><ProductId>13</ProductId><RollId>13176</RollId></SelectedProduct><SelectedProduct><ProductId>29</ProductId><RollId>3006</RollId></SelectedProduct><SelectedProduct><ProductId>29</ProductId><RollId>3003</RollId></SelectedProduct><SelectedProduct><ProductId>29</ProductId><RollId>8626</RollId></SelectedProduct><SelectedProduct><ProductId>29</ProductId><RollId>3004</RollId><Qty>182</Qty></SelectedProduct><SelectedProduct><ProductId>5</ProductId><RollId>7904</RollId></SelectedProduct></SelectedProducts>";

            DataSet ds = dmCe.ExecuteDs("webInsRezerve", xmlRezerve, xmlRezerveLines);
            int RezerveId = (int)ds.Tables[0].Rows[0][0];

            Sessions.Brand = "7 CAMICIE";
            Sessions.Season = "SS10";
            Sessions.Duration = "14 day(s)";
            Sessions.Notes = "Urgent !";
            Sessions.OrderRef = "121-B";
            Sessions.RequestId = RezerveId;
            Sessions.ReservedBy = "Kâsım GÜLCAN";
            Sessions.email = "kasimgulcan.karbel@gmail.com";
            Sessions.RezerveSummary = ds.Tables[1];
            */
            if (Request.QueryString["TrackNo"] != null)
            {
                int TrackNo = int.Parse(Request.QueryString["TrackNo"]);
            string cnnCe = System.Configuration.ConfigurationManager.ConnectionStrings["ce"].ConnectionString;
            ConfExpert.Utility.Data.DataManager dmCe = new ConfExpert.Utility.Data.DataManager(cnnCe);
            DataSet ds = dmCe.ExecuteDataset("web2GetRezerveSummary", TrackNo);
            DataRow drHeader = ds.Tables[0].Rows[0];
            DataTable dtDetail = ds.Tables[1];

            Sessions.Brand = drHeader["Brand"].ToString();
            Sessions.Season = drHeader["Season"].ToString();
            Sessions.Duration = drHeader["Duration"].ToString();
            Sessions.Notes = drHeader["Notes"].ToString();
            Sessions.OrderRef = drHeader["OrderRef"].ToString();
            Sessions.RequestId = (int)drHeader["WebRezerveId"];
            Sessions.ReservedBy = drHeader["ReservedBy"].ToString();
            Sessions.email = drHeader["Email"].ToString();
            Sessions.RezerveSummary = dtDetail;


            string newfile = Server.MapPath(String.Format("~/Reports/ReservationRequest/{0}.pdf", TrackNo));
            report.ExportToPdf(newfile);

            return;
            }



            string file = Server.MapPath(String.Format("~/Reports/ReservationRequest/{0}.pdf", Sessions.RequestId));
            report.ExportToPdf(file);
            
            string message = "Bu otomatik oluşturulmuş bir mesajdır. İlgili talep dosyasını aşağıdaki adreste bulabilirsiniz ;";
            message += "<br>" + Request.Url.ToString().ToLower().Replace("members/reservationreport.aspx", "Reports/ReservationRequest/") + string.Format("{0}.pdf", Sessions.RequestId);

            using (messenger.MessengerSoapClient messangerClient = new messenger.MessengerSoapClient())
            {
                messangerClient.SendEmail("ce", "ce", "ConfExpert.Online", "kasimgulcan.karbel@gmail.com", Sessions.Brand + " | Yeni Rezervasyon Talebi !", message);
            }
            
        }
    }
  

  

}